package com.donald.util;

import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPoolConfig;

import java.util.ResourceBundle;

public class JedisUtil {
    private static JedisPool jp =null;
    private static String host;
    private static int port;
    private static int maxTotal;
    private static int maxIdle;

    /**
     * jedis连接池静态代码块
     */
    static {
        ResourceBundle rb = ResourceBundle.getBundle("redis");
        host = rb.getString("redis.host");
        port = Integer.parseInt(rb.getString("redis.port"));
        maxTotal = Integer.parseInt(rb.getString("redis.port"));
        maxIdle = Integer.parseInt(rb.getString("redis.port"));
        JedisPoolConfig jpc = new JedisPoolConfig();
        jpc.setMaxTotal(maxTotal);//最大连接数
        jpc.setMaxIdle(maxIdle);//活动连接数
        jp = new JedisPool(jpc,host,port);
    }


    public static Jedis getJedis(){
        return jp.getResource();
    }
    //静态方法测试
    public static void main(String[] args) {
        JedisUtil.getJedis();
    }

}
